var app = getApp();
var ajax = require('../../utils/ajax.js');
var util = require('../../utils/util.js');
var common = require('../../utils/common.js');
var Pagination = require('../../utils/pagination.js');
var wxUtil = require('../../utils/wxUtil.js');
var MPage = require('../MPage.js');

Page(common.extendPage(MPage, {
    data: {
        dataLoaded: false,
        nextPageLoading: false,
        pageLoadedAll: false,

        list: [],
    },

    onLoad(options) {
        this._fetch();

    },

    onReachBottom() {
        _self.pagination && _self.pagination.loadNext();
    },

    _fetch() {
        var _self = this;

        _self.pagination = new Pagination({
            url: '/openapi/CActivity/myhaggleActList',
            params: {
            },
            beforeGetPage(page) {
                if (page > 1) {
                    _self.setData({
                        nextPageLoading: true
                    });
                }
            },
            getPageSuccess(page, data) {
                var result = data.result;
                var page1 = _self.data.page1;
                var list = _self.data.list || [];
                var curList = result['myActList'] || [];
                var data = {};

                if (page == 1) {
                    data = {
                        dataLoaded: true,
                    };
                }

                if (curList.length < 10) {
                    data.pageLoadedAll = true;
                }

                data.nextPageLoading = false;

                data.list = list.concat(curList);

                _self.setData(data);
            }
        });
    }

}));